package com.kkb.dao;

import com.kkb.pojo.Account;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AccountDao {
    // 新增账户
    @Insert("insert into tb_account values (#{id}, #{name}, #{money})")
    void addAccount(Account newAccount);

    // 删除账户
    @Delete("delete from tb_account where id = #{id}")
    void deleteAccountById(Integer id);

    // 修改账户
    @Update("update tb_account set name = #{name}, money = #{money} where id = ${id}")
    void updateAccountByAccount(Account newAccount);

    // 查询账户（根据ID查询）
    @Select("select * from tb_account where id = #{id}")
    Account findAccountById(Integer id);

    // 查询账户（根据姓名精确查询）
    @Select("select * from tb_account where name = #{name}")
    Account findAccountByName(String name);

    // 查询账户(根据用户名模糊查询)
    @Select("select * from tb_account where name like concat('%',#{name}, '%')")
    List<Account> findAccountsByName(String name);

    // 查询所有账户
    @Select("select * from tb_account")
    List<Account> findAllAccounts();
}
